﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "ElementUIWidget.h"
#include "Components/Button.h"
#include "Widget/SInputNumber.h"
#include "ElementUIInputNumber.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNumberTextChangedEvent, const FText&, Text);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnNumberTextExceptionEvent, const FText&, Text, EInputNumberException, Exception);

UCLASS(meta=(DisplayName="Input Number"))
class ELEMENTUIUMG_API UElementUIInputNumber : public UElementUIWidget
{
	GENERATED_BODY()

public:
	UElementUIInputNumber();
	virtual void SynchronizeProperties() override;

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	FText GetNumberText();

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetNumberText(FText NewText);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
    bool SetStepStrictly(bool value);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
    bool SetDisabled(bool value);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	float GetNumberStep() { return NumberStep; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetNumberStep(float NumberStep);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	FString GetMinValue() { return MinValue; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetMinValue(FString NewMinValue);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	FString GetMaxValue() { return MaxValue; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetMaxValue(FString NewMaxValue);

protected:
	virtual TSharedRef<SWidget> RebuildWidget() override;

	// #if WITH_EDITOR
	// 	virtual TSharedRef<SWidget> RebuildDesignWidget(TSharedRef<SWidget> Content) override;
	// #endif

protected:
	void HandleOnNumberTextChanged(const FText& Text);
	void HandleOnNumberTextException(const FText& InText, EInputNumberException Exception);
	// PROPERTY_BINDING_IMPLEMENTATION(FText, NumberText);

private:
	TSharedPtr<SInputNumber> InputNumberSlate;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	FText NumberText;
	// UPROPERTY()
	// FGetText NumberTextDelegate;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	float NumberStep;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	bool StepStrictly;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	bool Disabled;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	FString MinValue;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	FString MaxValue;

	UPROPERTY(EditAnywhere, Category=Number,meta = (AllowPrivateAccess = "true"))
	FSlateFontInfo NumberFont;

	UPROPERTY(BlueprintAssignable, Category=Number, meta= (AllowPrivateAccess = "true"))
	FOnNumberTextChangedEvent OnNumberTextChanged;

	UPROPERTY(BlueprintAssignable, Category=Number, meta= (AllowPrivateAccess = "true"))
	FOnNumberTextExceptionEvent OnOnNumberTextException;
	

private:
	UPROPERTY(EditAnywhere, Category=LeftButton,meta = (AllowPrivateAccess = "true"))
	float LeftButtonWidth;

	UPROPERTY(EditAnywhere, Category=LeftButton,meta = (AllowPrivateAccess = "true"))
	FButtonStyle LeftButtonStyle;

	UPROPERTY(BlueprintAssignable, Category=LeftButton,meta = (AllowPrivateAccess = "true"))
	FOnButtonClickedEvent OnLeftButtonClicked;

public:
	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	float GetLeftButtonWidth() { return LeftButtonWidth; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetLeftButtonWidth(float NewValue);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	FButtonStyle GetLeftButtonStyle() { return LeftButtonStyle; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetLeftButtonStyle(FButtonStyle NewValue);

protected:
	FReply OnLeftButtonClickedHandle();

private:
	UPROPERTY(EditAnywhere, Category=RightButton,meta = (AllowPrivateAccess = "true"))
	float RightButtonWidth;

	UPROPERTY(EditAnywhere, Category=RightButton,meta = (AllowPrivateAccess = "true"))
	FButtonStyle RightButtonStyle;

	UPROPERTY(BlueprintAssignable, Category=RightButton,meta = (AllowPrivateAccess = "true"))
	FOnButtonClickedEvent OnRightButtonClicked;

public:
	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	float GetRightButtonWidth() { return RightButtonWidth; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetRightButtonWidth(float NewValue);

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	FButtonStyle GetRightButtonStyle() { return RightButtonStyle; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|InputNumber")
	bool SetRightButtonStyle(FButtonStyle NewValue);

protected:
	FReply OnRightButtonClickedHandle();
};

